package ph.gov.marikina.mcsmtms.tests;

import static org.junit.Assert.assertTrue;

import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import ph.gov.marikina.mcsmtms.constants.GlobalConstants.Roads;
import ph.gov.marikina.mcsmtms.constants.GlobalConstants.SituationTypes;
import ph.gov.marikina.mcsmtms.constants.GlobalConstants.TrafficConditionTypes;
import ph.gov.marikina.mcsmtms.dao.ActivityFeedsDAO;
import ph.gov.marikina.mcsmtms.dao.MobileUserReportDAO;
import ph.gov.marikina.mcsmtms.dao.SituationReportDAO;
import ph.gov.marikina.mcsmtms.domain.MobileUserReport;
import ph.gov.marikina.mcsmtms.domain.SituationReport;
import ph.gov.marikina.mcsmtms.domain.SituationSegment;
import ph.gov.marikina.mcsmtms.domain.User;


public class MobileUserReportDAOImplTest {

	Logger log = Logger.getLogger(MobileUserReportDAOImplTest.class);

	/** The context. */
	private static ApplicationContext springContext = new ClassPathXmlApplicationContext(
			"spring/test-spring-config.xml");
	
	/** The application context. */
//	private static ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
//			"applicationContext.xml");
	
	@Before
	public void setUp() throws Exception {
	}

	@Test
	public void testAddSituationReport() {
		//fail("Not yet implemented");
		MobileUserReportDAO mobileUserReportDAO = (MobileUserReportDAO) springContext.getBean("mobileUserReportDAO");
		MobileUserReport mobileUserReport = new MobileUserReport();
		
		mobileUserReport.setRoad(Roads.BAYAN_BAYANAN.getCode());
		mobileUserReport.setSituation(SituationTypes.ACCIDENT.getCode());
		mobileUserReport.setTrafficCondition(TrafficConditionTypes.HEAVY.getCode());
		mobileUserReport.setReporter(18);
		mobileUserReport.setReportDateTime(new Date());
		mobileUserReport.setDescription("Test");
		mobileUserReport.setLocationLat(new Double(0.0));
		mobileUserReport.setLocationLng(new Double(0.0));
		mobileUserReport.setSpeed(new Double(0.0));
		
		//ActivityFeedsDAO notificationDAO = (ActivityFeedsDAO) springContext.getBean("notificationDAO");
//		List<Notification> notificationList = notificationDAO.getAllNotitications();
//		for(Notification notification : notificationList) {
//			System.out.println(notification.getReporter());
//		}
		
//		List<User> userList = notificationDAO.getAllUsers();
//		for(User user:userList) {
//			System.out.println(user.getFullName());
//		}
//		situationReport.setRoad(Roads.BAYAN_BAYANAN.getCode());
//		situationReport.setDirection(Direction.A_TO_B.getCode());
//		situationReport.setLastUpdateDateTime(new Date());
//		situationReport.setReporter(18);
//		situationReport.setReportSource(ReportSource.WEB.getCode());
//		situationReport.setStatus(Status.NEW.getCode());
//		
//		SituationSegment situationSegment = new SituationSegment();
//		situationSegment.setSituation(SituationTypes.ACCIDENT.getCode());
//		situationSegment.setAccessibleYn(true);
//		situationSegment.setTrafficCondition(TrafficConditionTypes.HEAVY.getCode());
//		situationSegment.setDescription("Test");
//		situationSegment.setStartLat(new Double(0.0));
//		situationSegment.setStartLng(new Double(0.0));
//		situationSegment.setEndLat(new Double(0.0));
//		situationSegment.setEndLng(new Double(0.0));
//		
//		List<SituationSegment> situationSegmentList = new ArrayList<SituationSegment>();
//		situationSegmentList.add(situationSegment);
//		situationReport.setSituationSegmentList(situationSegmentList);
//		
		mobileUserReportDAO.addMobileUserReport(mobileUserReport);
		
		List<MobileUserReport> mobileUserReportList = mobileUserReportDAO.getAllMobileUserReports();
		Assert.assertTrue(mobileUserReportList.size() > 0);
		//Assert
	}
	
	@Ignore
	public void testGetHazardMapSituationReports() {
		//fail("Not yet implemented");
		SituationReportDAO situationReportDAO = (SituationReportDAO) springContext
				.getBean("situationReportDAO");
		List<SituationReport> situationReportList = situationReportDAO.getHazardMapSituationReports();
		
		for(SituationReport situationReport : situationReportList) {
			System.out.println("SituationReportID: " + situationReport.getId());
			for(SituationSegment segment : situationReport.getSituationSegmentList()) {
				System.out.println("SituationSegmentID: " + segment.getId());
			}
			
		}
		
		assertTrue(situationReportList.size() > 0);
	}
	
}
